﻿using DevExpress.Pdf.Native;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace GluePathModule
{
    [XmlInclude(typeof(GluePathItemLine))]
    public class GluePathItemLine : GluePathItemBase
    {
        [Description("线的起点设定"), Category("直线设定")]
        public PointData Pos1
        {
            get;
            set;
        }
        [Description("线的终点设定"), Category("直线设定")]
        public PointData Pos2
        {
            get;
            set;
        }
        [Description("线的起点设定"), Category("直线转换")]
        public PointData Pos1Transfer
        {
            get;
            set;
        }
        [Description("线的终点设定"), Category("直线转换")]
        public PointData Pos2Transfer
        {
            get;
            set;
        }
        [Description("开始结束速度"), Category("速度设定")]
        public double 高速开始速度
        {
            get;
            set;
        }
        [Description("开始结束速度"), Category("速度设定")]
        public double 高速结束速度
        {
            get;
            set;
        }
        [Description("开始结束速度"), Category("速度设定")]
        public double 点胶开始速度
        {
            get;
            set;
        }
        [Description("开始结束速度"), Category("速度设定")]
        public double 点胶结束速度
        {
            get;
            set;
        }
        [Browsable(false)]
        public bool bUseZheight
        {
            get;
            set;
        }
        [Browsable(false)]
        public string UseZheightName1
        {
            get;
            set;
        }
        [Browsable(false)]
        public string UseZheightName2
        {
            get;
            set;
        }
        [Browsable(false)]
        public int iDrawStep
        {
            get;
            set;
        }
       
        public GluePathItemLine()
        {
            iDrawStep = 0;
            Name = "";
            Remark = "";
            UseZheightName1 = "";
            UseZheightName2 = "";
            Pos1 = new PointData();
            Pos2 = new PointData();
        }
        private double mouseDownX;
        private double mouseDownY;

        public override void DrawItem(DrawerControl drawer, DrawMode drawMode = DrawMode.UnitIsSelected)
        {
            base.DrawItem(drawer);
            if (drawMode == DrawMode.Background)
            {
                drawer.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Gray, 1), Pos1.X, Pos1.Y, Pos2.X, Pos2.Y);
                return;
            }
            else if (drawMode == DrawMode.UnitIsNotSelect)
            {
                drawer.DrawLine(new System.Drawing.Pen(System.Drawing.Color.White, 3), Pos1.X, Pos1.Y, Pos2.X, Pos2.Y);
                return;
            }

            if (空动作路径)
                drawer.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue, 3), Pos1.X, Pos1.Y, Pos2.X, Pos2.Y);
            else
                drawer.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Green, 3), Pos1.X, Pos1.Y, Pos2.X, Pos2.Y);

            if (Select)
            {
                drawer.DrawPoint(new System.Drawing.Pen(System.Drawing.Color.Red, 2), Pos1.X, Pos1.Y, 0.5);
                drawer.DrawPoint(new System.Drawing.Pen(System.Drawing.Color.Red, 2), Pos2.X, Pos2.Y, 0.5);
            }

        }
        private double AngleToHu(double dAngle)
        {
            return dAngle / 180.0 * Math.PI;
        }
        private double HuToAngle(double dHu)
        {
            return dHu / Math.PI * 180.0;
        }
        public override bool IsOnSelect(double dPosX, double dPosY, double dJudageDis)
        {
           
            double dMaxX, dMaxY, dMinX, dMinY;
            dMaxX = Pos1.X > Pos2.X ? Pos1.X : Pos2.X;
            dMaxY = Pos1.Y > Pos2.Y ? Pos1.Y : Pos2.Y;
            dMinX = Pos1.X < Pos2.X ? Pos1.X : Pos2.X;
            dMinY = Pos1.Y < Pos2.Y ? Pos1.Y : Pos2.Y;

            if (dPosX > dMinX - dJudageDis && dPosX < dMaxX + dJudageDis && dPosY > dMinY - dJudageDis && dPosY < dMaxY + dJudageDis)
            {
                if (Select == false)
                    Select = IsOnline(dPosX, dPosY, dJudageDis);
                return Select;
            }
            else
            {
                //Select = false;
                return Select;
            }

        }
        /// <summary>
        /// 获取两点的距离
        /// 作者：陈   时间：20200810
        /// </summary>
        /// <returns></returns>
        public double GetDisFrom2Points(double x1, double y1, double x2, double y2)
        {
            return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }


        ///
        ///点x1到线段x1-x2的距离
        /// 作者：陈   时间：20200810
        /// </summary>
        /// <returns></returns>
        public double GetDisFromPointToLine(double dPosX, double dPosY)
        {
            double space = 0;
            double a, b, c;
            a = GetDisFrom2Points(Pos1.X, Pos1.Y, Pos2.X, Pos2.Y);// lineSpace(x1, y1, x2, y2);// 线段的长度    
            b = GetDisFrom2Points(Pos1.X, Pos1.Y, dPosX, dPosY);// (x1,y1)到点的距离    
            c = GetDisFrom2Points(Pos2.X, Pos2.Y, dPosX, dPosY);// (x2,y2)到点的距离    
            if (c <= 0.000001 || b <= 0.000001)
            {
                space = 0;
                return space;
            }
            if (a <= 0.000001)
            {
                space = b;
                return space;
            }
            if (c * c >= a * a + b * b)
            {
                space = b;
                return space;
            }
            if (b * b >= a * a + c * c)
            {
                space = c;
                return space;
            }
            double p = (a + b + c) / 2;// 半周长    
            double s = Math.Sqrt(p * (p - a) * (p - b) * (p - c));// 海伦公式求面积    
            space = 2 * s / a;// 返回点到线的距离（利用三角形面积公式求高）    
            return space;
        }
        private bool IsOnline(double dPosX, double dPosY, double dJudageDis)
        {
            double dDistance = GetDisFromPointToLine(dPosX, dPosY);
            return Math.Abs(dDistance) < dJudageDis;
        }
        public override bool GetLastPoint(out double dPosX, out double dPosY, out double dPosZ, out double dPosU)
        {
            dPosX = Pos2.X;
            dPosY = Pos2.Y;
            dPosZ = Pos2.Z;
            dPosU = Pos2.U;
            return true;
        }
        public override bool GetFirstPoint(out double dPosX, out double dPosY, out double dPosZ, out double dPosU)
        {
            
            dPosX = Pos1.X;
            dPosY = Pos1.Y;
           
            dPosZ = Pos1.Z;
            dPosU = Pos1.U;
            return true;
        }
       
        
        public override GluePathItemBase CopyItem()
        {
            GluePathItemLine itemNew = (GluePathItemLine)MemberwiseClone();
            itemNew.Pos1 = new PointData(Pos1);
            itemNew.Pos1Transfer = new PointData(Pos1Transfer);
            itemNew.Pos2 = new PointData(Pos2);
            itemNew.Pos2Transfer = new PointData(Pos2Transfer);
            return itemNew;
        }
        override public GluePathItemBase Paste()
        {
            return CopyItem();
        }
        public override void OffSetItem(double dOffSetX, double dOffSetY)
        {
            Pos1.X = Pos1.X + dOffSetX;
            Pos1.Y = Pos1.Y + dOffSetY;
            Pos2.X = Pos2.X + dOffSetX;
            Pos2.Y = Pos2.Y + dOffSetY;
        }
        override public void PathUnitMouseDown(double dMouseX, double dMouseY, double dScandle)
        {
            if (Select == false)
                return;
            if (iAdjustStep == 0)
            {

                if (dMouseX > (Pos1.X - (5 / dScandle)) && dMouseX < (Pos1.X + (5 / dScandle)) && dMouseY > (Pos1.Y - (5 / dScandle)) && dMouseY < (Pos1.Y + (5 / dScandle)))
                {
                    iAdjustStep = 1;
                }
                else if (dMouseX > (Pos2.X - (5 / dScandle)) && dMouseX < (Pos2.X + (5 / dScandle)) && dMouseY > (Pos2.Y - (5 / dScandle)) && dMouseY < (Pos2.Y + (5 / dScandle)))
                {
                    iAdjustStep = 2;
                }
                else if (IsOnline(dMouseX, dMouseY, (5 / dScandle)))
                {
                    mouseDownX = dMouseX;
                    mouseDownY = dMouseY;
                    iAdjustStep = 3;
                }

            }
        }
        override public void PathUnitMouseMove(double dMouseX, double dMouseY)
        {
            if (Select == false)
                return;
            if (iAdjustStep == 1)
            {
                Pos1.X = dMouseX;
                Pos1.Y = dMouseY;

            }
            if (iAdjustStep == 2)
            {
                Pos2.X = dMouseX;
                Pos2.Y = dMouseY;

            }
            if (iAdjustStep == 3)
            {
                double dOffSetX = dMouseX - mouseDownX;
                double dOffSetY = dMouseY - mouseDownY;
                Pos1.X = Pos1.X + dOffSetX;
                Pos1.Y = Pos1.Y + dOffSetY;
                Pos2.X = Pos2.X + dOffSetX;
                Pos2.Y = Pos2.Y + dOffSetY;
                mouseDownX = dMouseX;
                mouseDownY = dMouseY;
            }
        }
        override public void PathUnitMouseUp(double dMouseX, double dMouseY)
        {
            if (Select == false)
                return;
            if (iAdjustStep == 1)
            {
                Pos1.X = dMouseX;
                Pos1.Y = dMouseY;
                iAdjustStep = 0;

            }
            if (iAdjustStep == 2)
            {
                Pos2.X = dMouseX;
                Pos2.Y = dMouseY;
                iAdjustStep = 0;


            }
            if (iAdjustStep == 3)
            {
                double dOffSetX = dMouseX - mouseDownX;
                double dOffSetY = dMouseY - mouseDownY;
                Pos1.X = Pos1.X + dOffSetX;
                Pos1.Y = Pos1.Y + dOffSetY;
                Pos2.X = Pos2.X + dOffSetX;
                Pos2.Y = Pos2.Y + dOffSetY;
                mouseDownX = dMouseX;
                mouseDownY = dMouseY;
                iAdjustStep = 0;
            }
        }
        public override void OffSetPos(double dOffSetX, double dOffSetY, double dOffSetZ)
        {
            Pos1.X = Pos1.X + dOffSetX;
            Pos1.Y = Pos1.Y + dOffSetY;
            Pos1.Z = Pos1.Z + dOffSetZ;

            Pos2.X = Pos2.X + dOffSetX;
            Pos2.Y = Pos2.Y + dOffSetY;
            Pos2.Z = Pos2.Z + dOffSetZ;

        }
        public override void SetZPos(double dSetPosZ)
        {

            Pos1.Z = dSetPosZ;

            Pos2.Z = dSetPosZ;


        }
        public override void SetUPos(double dSetPosU)
        {

            Pos1.U = dSetPosU;

            Pos2.U = dSetPosU;


        }
        public override void UpdateZheight(double dZHeight)
        {
            
            
           
              
                Pos1.Z = dZHeight;
           
               
                Pos2.Z = dZHeight;
            
        }
        public override void WriteToDxf(netDxf.DxfDocument dxfDocument)
        {
          
            netDxf.Entities.Line lineTemp = new netDxf.Entities.Line(new netDxf.Vector2(Pos1.X, Pos1.Y), new netDxf.Vector2(Pos2.X, Pos2.Y));
            if (this.空动作路径)
            {
                lineTemp.Color = new netDxf.AciColor(System.Drawing.Color.Blue);
            }
            else
            {
                lineTemp.Color = new netDxf.AciColor(System.Drawing.Color.Green);
            }

            dxfDocument.Entities.Add(lineTemp);
        }
        public override void GetItemMinMaxXY(out double dMinX, out double dMinY, out double dMaxX, out double dMaxY)
        {
            base.GetItemMinMaxXY(out dMinX, out dMinY, out dMaxX, out dMaxY);

            if (Pos1.X < Pos2.X)
            {
                dMinX = Pos1.X;
            }
            else
            {
                dMinX = Pos2.X;
            }
            if (Pos1.Y < Pos2.Y)
            {
                dMinY = Pos1.Y;
            }
            else
            {
                dMinY = Pos2.Y;
            }

            if (Pos1.X > Pos2.X)
            {

                dMaxX = Pos1.X;

            }
            else
            {
                dMaxX = Pos2.X;
            }

            if (Pos1.Y > Pos2.Y)
            {
                dMaxY = Pos1.Y;
            }
            else
            {
                dMaxY = Pos2.Y;
            }
        }

        public override void UpdateEndPos(double dNewEndX, double dNewEndY)
        {
            Pos2.X = dNewEndX;
            Pos2.Y = dNewEndY;
        }
        public override void UpdateStartPos(double dNewStartX, double dNewStartY)
        {
            Pos1.X = dNewStartX;
            Pos1.Y = dNewStartY;
        }
        public override void PushItem(List<MotionItemBase> motionItems, GluePathGroup gluePathGroup, GluePathUnit gluePathUnit, int indexId,double dOffsetZ)
        {
            

            SpdData spdXYGlue = new SpdData();
            SpdData spdXYH = new SpdData();
            SpdData spdZH = new SpdData();


            double dFirstPosX, dFirstPosY, dFirstPosZ, dFirstPosU;
            GetFirstPoint(out dFirstPosX, out dFirstPosY, out dFirstPosZ, out dFirstPosU);

            #region 判断胶路类型
            bool bIsFirstItem = false;
            bool bisFinalItem = false;
            bool bContinueWithBeforeItem = false;
            bool bContinueWithAferItem = false;
            bool bIsContinueWithAferAndAfterIsOnGlue = false;
            if (indexId == 0)
            {
                bIsFirstItem = true;
            }
            if (indexId == (gluePathUnit.listContinueItems.Count - 1))
            {
                bisFinalItem = true;
            }
            if (indexId == 0)
            {

            }
            else
            {
                double dBeforeItemPosX, dBeforeItemPosY, dBeforeItemPosZ, dBeforeItemPosU;
                gluePathUnit.listContinueItems[indexId - 1].GetLastPoint(out dBeforeItemPosX, out dBeforeItemPosY,
                    out dBeforeItemPosZ, out dBeforeItemPosU);
                if (Math.Abs(dBeforeItemPosX - dFirstPosX) < 0.5 && Math.Abs(dBeforeItemPosY - dFirstPosY) < 0.5 && Math.Abs(dBeforeItemPosZ - dFirstPosZ) < 0.5)
                {
                    bContinueWithBeforeItem = true;
                }
            }
            if (indexId == (gluePathUnit.listContinueItems.Count - 1))
            {
                bContinueWithAferItem = false;
            }
            else
            {
                double dNextItemPosX, dNextItemPosY, dNextItemPosZ, dNextItemPosU;
                double dCurrentEndPosX, dCurrentEndPosY, dCurrentEndPosZ, dCurrentEndPosU;
                GetLastPoint(out dCurrentEndPosX, out dCurrentEndPosY, out dCurrentEndPosZ, out dCurrentEndPosU);
                gluePathUnit.listContinueItems[indexId + 1].GetFirstPoint(out dNextItemPosX, out dNextItemPosY,
                    out dNextItemPosZ, out dNextItemPosU);
                if (Math.Abs(dCurrentEndPosX - dNextItemPosX) < 0.5 && Math.Abs(dCurrentEndPosY - dNextItemPosY) < 0.5 && Math.Abs(dCurrentEndPosZ - dNextItemPosZ) < 0.5)
                {
                    bContinueWithAferItem = true;
                    if (gluePathUnit.listContinueItems[indexId + 1].空动作路径 == false && gluePathUnit.listContinueItems[indexId + 1].Disable == false)
                    {
                        bIsContinueWithAferAndAfterIsOnGlue = true;
                    }
                }
            }
            #endregion

            #region 速度设定

            if (使用单独涂胶速度)
            {
                spdXYGlue.dMoveSpd = 单独涂胶速度;
            }
            else
            {
                if (空动作路径)
                {
                    spdXYGlue.dMoveSpd = gluePathUnit.全局XY高速速度;
                }
                else
                {
                    spdXYGlue.dMoveSpd = gluePathUnit.全局涂胶速度;
                }
            }
            spdXYH.dStartSpd = gluePathUnit.全局开始速度;
            spdXYH.dMoveSpd = gluePathUnit.全局XY高速速度;
            spdXYH.dEndSpd = gluePathUnit.全局结束速度;
            spdXYH.dAcc = gluePathUnit.全局加速度;
            spdXYH.dDec = gluePathUnit.全局减速度;
            spdZH.dStartSpd = gluePathUnit.全局开始速度;
            spdZH.dMoveSpd = gluePathUnit.全局Z高速速度;
            spdZH.dEndSpd = gluePathUnit.全局结束速度;
            spdZH.dAcc = gluePathUnit.全局加速度;
            spdZH.dDec = gluePathUnit.全局减速度;
            if (bIsFirstItem && bisFinalItem)//只有一个点
            {
                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            if (bIsFirstItem && (!bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程的第一个点和后面有连接
            {

                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;

            }
            if (!bIsFirstItem && (!bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程中间点，没有和前面的连接，与后面的连接
            {

                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;

            }
            if (!bIsFirstItem && (bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程中间点，和前面的连接，与后面的连接
            {

                spdXYGlue.dStartSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dEndSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            if (!bIsFirstItem && (bContinueWithBeforeItem) && (!bContinueWithAferItem) && (!bisFinalItem))//流程中间点，和前面的连接，没有与后面的连接
            {
                spdXYGlue.dStartSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;

            }
            if (!bIsFirstItem && (!bContinueWithBeforeItem) && (!bContinueWithAferItem) && (!bisFinalItem))//流程中间点，没有和前面的连接，没有与后面的连接
            {
                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            if (!bIsFirstItem && (bContinueWithBeforeItem) && (!bContinueWithAferItem) && (bisFinalItem))//流程最后一个线段，和前面连接
            {
                spdXYGlue.dStartSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            if (!bIsFirstItem && (!bContinueWithBeforeItem) && (!bContinueWithAferItem) && (bisFinalItem))//流程最后一个线段，没有和前面连接
            {
                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            #endregion

            TranferPosToCur(gluePathUnit, bContinueWithBeforeItem, motionItems,dOffsetZ);

            #region 轨迹设定


            if (bContinueWithBeforeItem == false)
            {
                MotionItemLine motionItemLineUp = new MotionItemLine(spdXYH, Pos1Transfer);
                motionItemLineUp.Point.Z = gluePathUnit.全局安全高度Z;
                motionItems.Add(motionItemLineUp);
                MotionItemLine motionItemLineStart = new MotionItemLine(spdZH, Pos1Transfer);
                motionItems.Add(motionItemLineStart);

            }

            if (空动作路径 == false)
            {
                MotionItemOutput motionItemOutput = new MotionItemOutput();
                motionItemOutput.On = true;
                motionItems.Add(motionItemOutput);
            }

            if (this.开胶后延时时间 > 0)
            {
                MotionItemDelay motionItemDelay = new MotionItemDelay();
                motionItemDelay.dDelayTime = this.开胶后延时时间;
                motionItems.Add(motionItemDelay);
            }

            

            MotionItemLine motionItemLine = new MotionItemLine(spdXYGlue, Pos2Transfer);
            motionItemLine.dEndU = Pos2Transfer.U;
            motionItems.Add(motionItemLine);

            if (bIsContinueWithAferAndAfterIsOnGlue == false)
            {
                MotionItemOutput motionItemOutput = new MotionItemOutput();
                motionItemOutput.On = false;
                motionItemOutput.dEndU = Pos2Transfer.U;
                motionItems.Add(motionItemOutput);
                
            }
            if (bContinueWithAferItem == false)
            {
                MotionItemLine motionItemLineUp = new MotionItemLine(spdZH, Pos2Transfer);
                motionItemLineUp.Point.Z = gluePathUnit.全局安全高度Z;
                motionItemLineUp.dEndU = Pos2Transfer.U;
                motionItems.Add(motionItemLineUp);
            }
            #endregion
        }

        private void TranferPosToCur(GluePathUnit gluePathUnit, bool bContinueWithBeforeItem, List<MotionItemBase> motionItems,double dOffsetZ)
        {
            PointData Pos1Temp = new PointData(Pos1);
            PointData Pos2Temp = new PointData(Pos2);

            if (bContinueWithBeforeItem)
            {
                Pos1Temp.U = motionItems[motionItems.Count - 1].dEndU;
                Pos2Temp.U = motionItems[motionItems.Count - 1].dEndU;
            }
            PointData pointDataLocalPos1 = WhereAtLocal(Pos1Temp, gluePathUnit.StandardLocalX, gluePathUnit.StandardLocalY, gluePathUnit.StandardLocalU);
            Pos1Transfer = TranLocalToMotor(pointDataLocalPos1, gluePathUnit.CurrentLocalX, gluePathUnit.CurrentLocalY, gluePathUnit.CurrentLocalU);
            AddToolOffSet(gluePathUnit, Pos1Transfer);

            PointData pointDataLocalPos12 = WhereAtLocal(Pos2Temp, gluePathUnit.StandardLocalX, gluePathUnit.StandardLocalY, gluePathUnit.StandardLocalU);
            Pos2Transfer = TranLocalToMotor(pointDataLocalPos12, gluePathUnit.CurrentLocalX, gluePathUnit.CurrentLocalY, gluePathUnit.CurrentLocalU);
            AddToolOffSet(gluePathUnit, Pos2Transfer);

            Pos1Transfer.Z = Pos1Transfer.Z - dOffsetZ;
            Pos2Transfer.Z = Pos2Transfer.Z - dOffsetZ;
        }
        
        //public override FiveInPutData GetItem()
        //{
        //    FiveInPutData newItem = new FiveInPutData();
        //    newItem.strType = "Line";
        //    newItem.Endpos[0] = Pos2X;
        //    newItem.Endpos[1] = Pos2Y;
        //    newItem.Endpos[2] = Pos2Z;
        //    newItem.Endpos[3] = Pos2U;
        //    newItem.Endpos[4] = Pos2U;
        //    //
        //    return newItem;
        //}
    }
}
